from fastapi import FastAPI
from tortoise.contrib.fastapi import HTTPNotFoundError, register_tortoise
from tortoise import Tortoise
from app.models import myUser


# database.py
TORTOISE_ORM = {
    # 'connections': {
    #     'default': {
    #         'engine': 'tortoise.backends.asyncpg',  # PostgreSQL
    #         # 'engine': 'tortoise.backends.mysql',  # MySQL or Mariadb
    #         'credentials': {
    #             'host': '192.168.1.181',
    #             'port': '5432',
    #             'user': 'postgres',
    #             'password': '123456',
    #             'database': 'fastapi',
    #             "minsize": 1,
    #             "maxsize": 5,
    #             'charset': 'utf8mb4',
    #             "echo": True
    #         }
    #     },
    # },
    # "connections": {"default": "mysql://root:zxc123456@192.168.137.130:3306/fastapi"},
    "connections": {'default': 'postgres://postgres:123456@localhost:5432/fastapi'},
    'apps': {
        'models': {
            # models:models 找到对应自定义的model.py
            'models': [  # aerich.models迁移模型
                'aerich.models',
                'app.models.myUser'
            ],
            'default_connection': 'default',
        }
    },
    'use_tz': False,
    'timezone': 'Asia/Shanghai'
}

# config = {
#     'db_url': 'postgres://user:password@localhost/dbname',  # 替换为你的 PostgreSQL 连接信息
#     'modules': {
#         'tortoise.backends.postgres': {
#             'sslmode': 'disable'  # 可选的，根据你的 PostgreSQL 配置调整
#         }
#     },
#     'generate_schemas': True  # 自动创建表结构
# }

